package task

import (
	"xr-game-server/core/event"
	"xr-game-server/gamecfg"
	"xr-game-server/gameevent"
)

func initFriend() {
	event.Sub(gameevent.OnlyOnceAddFriendEvent, addFriend)
}

func addFriend(data any) {
	if data == nil {
		return
	}
	friendCfgs, ok := gamecfg.TaskTypeMap[AddFriend]
	if !ok {
		return
	}
	eventData := data.(*gameevent.AddFriendEventData)
	for _, friendCfg := range friendCfgs {
		task := gamecfg.GetTaskById(friendCfg.Id)
		if task == nil {
			continue
		}
		chkCommonTask(friendCfg.Id, eventData.RoleId, 1)
	}
}
